<!DOCTYPE html>
<html lang="zh-cn">
	<head>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1">
	    <#include "/common/meta.ftl"/>
	    <#include "/common/form.ftl"/>
	    <#include "/common/ztree.ftl"/>
		<script>
			$(function(){
				$("#btnRole").click(function(){
					document.location.href = "roleForm?roleId=${roleId}";
				});
				$("#btnUser").click(function(){
					document.location.href = "grantUser2?roleId=${roleId}";
				});
				var zNodes;
				$.ajax({  
			        async : false,  
			        cache:false,  
			        type: 'POST',  
			        dataType : "json",  
			        url: "./roleAppTree?roleId=${roleId}",  
			        contentType: "application/x-www-form-urlencoded; charset=utf-8", 
			        error: function () {
			            alert('请求失败');  
			        },  
			        success:function(data){    
			            zNodes = data;  
			        }  
			    });
				$.fn.zTree.init($("#tree1"), setting, zNodes);
			});
			var setting = {
				check: {
					enable: true,
					chkboxType:  { "Y" : "", "N" : "" }
				},
				data: {
					simpleData: {
						enable: true
					}
				},
				callback: {
					beforeCollapse: beforeCollapse,
					onCheck: zTreeOnCheck
				}
			};
			function beforeCollapse(treeId, treeNode) {
				return true;
			}
			function zTreeOnCheck(event, treeId, treeNode) {
				if(treeId=='tree1'){
					update(treeNode.id, treeNode.checked);
				}else{
					update(treeNode.id, treeNode.checked);
				}
			}
			function update(appID, type){
				var operation = 1;
				if(type){
					operation = 1;
				}else{
					operation = 0;
				}
				$.getJSON("roleAppJSave", { type:operation,roleId: '${roleId}', appID: appID }, function(json){
					if(json.success){
						var msg = new top.$.zui.Messager('提示消息：'+json.msg, {
		                	type : 'success',
		                	fade : true,
		                	//placement : 'bottom-right',
		                	icon : 'ok-sign',
		                	time : 3000,
		                	scale : true
		                });
		                msg.show();
					}
				});
			}
		</script>
		<style>
			.ui-layout-resizer { /* all 'resizer-bars' */ 
				background: #DDD; 
			} 
			.ui-layout-pane-west { /* west pane */ 
				background-color: #EEE !important;
				overflow: auto;
				margin:5px;
			} 
		</style>
	</head>
	<body style="padding:5px;">
		<div class="panel panel-primary">
			<div class="panel-heading" style="">
				<strong>
				<i class="icon-pencil"></i> 设置角色【${roleName!''}】权限
				</strong>
			</div>
			<div class="panel-body" style="padding:5px;">
			<form id="form" class="form-horizontal " role="form" method='post' action="./channelSave">
				<div class="form-group">
		          	<div class="col-md-12" style="text-align:right;align:right;">
		             	<button class="btn btn-warning" id="btnUser" name="btnUser" type="button"><i class="icon icon-user"></i> 用户</button>
						<button class="btn" type="button" onclick="location.href='./role'"><i class="icon icon-reply"></i> 返回</button>		             	
		          	</div>
		        </div>
				<table class="table" style="margin:0px;">
					<tbody>
						<tr>
					      	<td valign="top" align=center style="text-align:center;">
					     		<ul id="tree1" class="ztree" ></ul>
					      	</td>
					    </tr>
					</tbody>
				</table>
	    	</form>
		  	</div>
	    </div>
	</body>
</html>